/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once
#include "DBManager/IRepository/Input/Subcase/ISubcaseRepository.h"
#include "DBManager/IService/Input/Subcase/ISubcaseService.h"

/// @brief Subcase Data manipulation interface

SG_DBMANAGER_NAMESPACE_OPEN
class DBManager_DECLSPEC SubcaseService : public ISubcaseService
{
  public:
    explicit SubcaseService (DBServiceFactory* const dbServiceFactory, ISubcaseRepository& repos);
    ~SubcaseService ();

    /// @brief 初始化仓库，只能初始化一次 每次初始化都会被覆盖
    /// @param entity
    void Initial (SG::Utility::SGParameter entity) override;

    /// @brief 返回整个subcse的信息
    SG::Utility::SGParameter GetSubcase () override;

    /// @brief 获取所有的SubCase ID
    std::vector<SG::DataStructure::Common::Id> GetAllSubcaseID () override;

    /// @brief 获取某一个SubCase
    /// @param subcaseId
    SG::Utility::SGParameter FindSubCase (SG::DataStructure::Common::Id subcaseId) override;

    /// @brief 获取所有的SubCase ID
    /// @param subcaseId subcaseId的vector
    std::set<SG::DataStructure::Common::Id> GetLoadsetIds (const std::vector<SG::DataStructure::Common::Id>& subcaseId) override;

    SG::DataStructure::Common::Status CopyData (DBServiceFactory* const dest) override;

    SG::DataStructure::FEM::SOLType GetSOLType (SG::DataStructure::Common::Id subcaseId) override;

  private:
    ISubcaseRepository&      m_repository;
    bool                     m_upToDate = false;  // 记录m_data是不是最新的，在initial后改为false，在m_data更新后为true;
    SG::Utility::SGParameter m_data;              // 记录subcase数据
    DBServiceFactory* const  m_SerFactory;        // 当前service的工厂方便查询其他service
};

SG_DBMANAGER_NAMESPACE_CLOSE
